/**
 * 由于目标网络不稳定 每一步都要有校验是否成功
 * 期待什么
 */

export class ElementNotFound {
    message: string;
    constructor(msg: string) {
        this.message = msg;
    }
}
export class WaitForCore {
    clickButton(btn: UiObject) {
        if (!btn) throw new ElementNotFound(`按钮不能为空`)
        if (btn.clickable()) {
            return btn.click()
        } else {
            const bounds = btn.bounds();
            click(bounds.centerX(), bounds.centerY());
            return true;
        }
    }
}
export class WaitForMyWalletAppear extends WaitForCore {
    do() {
        while (this.while()) {
            this.clickButton(selector().descMatches(/我/).visibleToUser(true).findOne())
            sleep(1000)
        }
    }
    while() {
        const item = selector().idMatches(/.*?main_title$/).textMatches(/^我的钱包$/).findOnce()
        if(!item) log(`没有找到我的钱包`)
        if(item) return false;
        return true;
    }
}

